﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace AssessmentTool.Controls
{
    public partial class Comment : UserControl
    {
        public FrameworkElement SetContent
        {
            get { return (FrameworkElement)GetValue(SetContentProperty); }
            set { SetValue(SetContentProperty, value); }
        }

        public static readonly DependencyProperty SetContentProperty =
            DependencyProperty.Register("SetContent", typeof(FrameworkElement), typeof(Comment), new PropertyMetadata(null, new PropertyChangedCallback(OnSetContentChanged)));
        private static void OnSetContentChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            ((Comment)d).OnSetContentChanged(e);
        }

        public String AnchorPointY
        {
            get { return (String)GetValue(AnchorPointXProperty); }
            set {  SetValue(AnchorPointXProperty, value);  }
        }

        private double anchorPointX;

        public static readonly DependencyProperty AnchorPointXProperty =
            DependencyProperty.Register("AnchorPointX", typeof(String), typeof(Comment), new PropertyMetadata(null, new PropertyChangedCallback(OnAnchorPointXChanged)));
        private static void OnAnchorPointXChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            Comment c = (Comment)d;
            String valore = (String)e.NewValue;
            if (valore != null)
            {
                double anchorPointX = Double.Parse(valore);
                c.punto1.EndPoint = new Point(anchorPointX - 5,c.punto1.EndPoint.Y);
                c.punto2.StartPoint = new Point(c.punto1.EndPoint.X, c.punto2.StartPoint.Y);
                c.punto2.EndPoint = new Point(anchorPointX, c.punto2.EndPoint.Y);
                c.punto3.StartPoint = new Point(c.punto2.EndPoint.X, c.punto3.StartPoint.Y);
                c.punto3.EndPoint = new Point(anchorPointX + 5, c.punto3.EndPoint.Y);
                c.punto4.StartPoint = new Point(c.punto3.EndPoint.X, c.punto4.StartPoint.Y);
                
            }
        }


        protected virtual void OnSetContentChanged(DependencyPropertyChangedEventArgs e)
        {

            if (SetContent != null)
                BoxContent.Content = SetContent;
        }
        public Comment()
        {
            InitializeComponent();
        }
    }
}
